import { createRouter, createWebHistory } from 'vue-router';
import Home from '../views/index.vue';
import viewsModuleList from './viewsModuleList'

const createRoutes = () => {
    return viewsModuleList.map(e => createComponent(e.name, e.title, e.component))
}

const createComponent = (name, title, component, keepalive = true) => {
    const componentObj = {
        path: '/' + name,
        name,
        component,
        meta: { title, keepalive }
    }
    return componentObj
}

const routes = [
    { path: '/', name: 'home', component: Home, },
    ...createRoutes()
];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

export default router
